class TagsController < ApplicationController

  def new

  end

  def create
    if params[:tags][:name].blank?
      render :new
    else
      @tag_names = instance_eval("%w(#{params[:tags][:name]})")
      @customers = Customer.find(params[:customer_id])
      @first = @customers.first      
      @tags = @tag_names.each_with_object([]) do |name, tags|
        tags << Tag.find_or_create_by_name(name).added_to_customers(@customers)
      end
    end
  end

  def unbundle_some
    @customer_tags = CustomerTag.where(['customer_id in (?) and tag_id in (?)', params[:customer_id], params[:tag_id]])
    @customer_tags.each do |customer_tag|
      customer_tag.destroy
    end    
  end

  def unbundle_one
    unbundle_some
  end
end
